checkBinAvailability() {
    which fabric-ca-server >/dev/null && which fabric-ca-client >/dev/null
    return $?
}

setServerEnvVars() {
    export FABRIC_CA_SERVER_TLS_ENABLED=true

    if [ $ORG_NAME == "org1" ]; then
        export FABRIC_CA_SERVER_CA_NAME=ca-org1
        export FABRIC_CA_SERVER_CSR_CN=ca.org1.lab805.com
        export FABRIC_CA_SERVER_PORT=7054
        export FABRIC_CA_SERVER_OPERATIONS_LISTENADDRESS=127.0.0.1:9443
    elif [ $ORG_NAME == "org2" ]; then
        export FABRIC_CA_SERVER_CA_NAME=ca-org2
        export FABRIC_CA_SERVER_CSR_CN=ca.org2.lab805.com
        export FABRIC_CA_SERVER_PORT=8054
        export FABRIC_CA_SERVER_OPERATIONS_LISTENADDRESS=127.0.0.1:10443
    elif [ $ORG_NAME == "ordererOrg" ]; then
        export FABRIC_CA_SERVER_CA_NAME=ca-orderer
        export FABRIC_CA_SERVER_CSR_CN=ca.orderer.lab805.com
        export FABRIC_CA_SERVER_PORT=9054
        export FABRIC_CA_SERVER_OPERATIONS_LISTENADDRESS=127.0.0.1:11443
    else
        printf "Invalid orderer name: '%s'\n" $ORG_NAME
        exit 1
    fi
}

setClientHome() {
    if [ $ORG_NAME == "ordererOrg" ]; then
        export FABRIC_CA_CLIENT_HOME="${WORKING_DIR}/client/ordererOrganizations/lab805.com"
        export FABRIC_CA_CLIENT_CSR_CN="lab805.com"
    else
        export FABRIC_CA_CLIENT_HOME="${WORKING_DIR}/client/peerOrganizations/${ORG_NAME}.lab805.com"
        export FABRIC_CA_CLIENT_CSR_CN="${ORG_NAME}.lab805.com"
    fi
}
